SOURCES_LIBEMBER := $(wildcard libember/*.c)
SOURCES_CONSOLE := $(wildcard ember_console/*.c)
SOURCES_EMBER := $(wildcard ember/*.c)
SOURCES_PROTON := $(wildcard ember_proton/*.c)

OBJECTS_LIBEMBER := $(patsubst %.c, %.o, $(SOURCES_LIBEMBER))
OBJECTS_CONSOLE := $(patsubst %.c, %.o, $(SOURCES_CONSOLE))
OBJECTS_EMBER := $(patsubst %.c, %.o, $(SOURCES_EMBER))
OBJECTS_PROTON := $(patsubst %.c, %.o, $(SOURCES_PROTON))

COMPILE_LIBRARY = gcc -shared -WL -lc
COMPILE_EXECUTABLE = gcc -WL -lc

TARGET_LIBEMBER = libember.so
TARGET_CONSOLE = ember_console_emb.so
TARGET_EMBER = emberi
TARGET_PROTON = ember_proton_emb.so

COMPILE = gcc -std=c89 -fPIC -g -Wall

all: $(TARGET_LIBEMBER) $(TARGET_CONSOLE) $(TARGET_EMBER) $(TARGET_PROTON)

install:
	cp $(TARGET_LIBEMBER) /usr/lib
	cp $(TARGET_CONSOLE) /usr/lib
	cp $(TARGET_PROTON) /usr/lib
	cp $(TARGET_EMBER) /usr/bin

basic: $(TARGET_EMBER)

$(TARGET_EMBER): $(TARGET_LIBEMBER) $(TARGET_CONSOLE) $(OBJECTS_EMBER)
	$(COMPILE_EXECUTABLE) -o $(TARGET_EMBER) $(OBJECTS_EMBER) -lc -ldl -lember -L.\
	
$(TARGET_CONSOLE): $(TARGET_LIBEMBER) $(OBJECTS_CONSOLE)
	$(COMPILE_LIBRARY) -o $(TARGET_CONSOLE) $(OBJECTS_CONSOLE) -lc -lember -L.\
	
$(TARGET_PROTON): $(TARGET_LIBEMBER) $(OBJECTS_PROTON)
	$(COMPILE_LIBRARY) -o $(TARGET_PROTON) $(OBJECTS_PROTON) -lc -lember -lSDL -lGL -L.\
	
$(TARGET_LIBEMBER): $(OBJECTS_LIBEMBER)
	$(COMPILE_LIBRARY) -o $(TARGET_LIBEMBER) $(OBJECTS_LIBEMBER)

%.o: %.c
	$(COMPILE) -c -o $@ $<

clean:
	rm -rf ./*.o $(TARGET_LIBEMBER) $(TARGET_CONSOLE) $(TARGET_EMBER) $(TARGET_PROTON) $(OBJECTS_LIBEMBER) $(OBJECTS_CONSOLE) $(OBJECTS_EMBER) $(OBJECTS_PROTON)

